﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Model;
using System.Collections.Generic;
namespace DAL
{
    /// <summary>
    /// 数据访问类:PMS_ProjectEvolve
    /// </summary>
    public class PMS_ProjectEvolveDAL
    {
        public PMS_ProjectEvolveDAL()
        { }
        #region  Method

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(PMS_ProjectEvolve model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update PMS_ProjectEvolve set ");
            strSql.Append("startDate=@startDate,");
            strSql.Append("planEndDate=@planEndDate,");
            strSql.Append("completeDate=@completeDate,");
            strSql.Append("principal=@principal");
            strSql.Append(" where id=@id");

            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int),
					new SqlParameter("@startDate", SqlDbType.DateTime),
					new SqlParameter("@planEndDate", SqlDbType.DateTime),
					new SqlParameter("@completeDate", SqlDbType.DateTime),
                    new SqlParameter("@principal",SqlDbType.NVarChar,50)};
            parameters[0].Value = model.id;
            if (model.startDate == null || model.startDate == DateTime.MinValue)
            {
                parameters[1].Value = DBNull.Value;
            }
            else
            {
                parameters[1].Value = model.startDate;
            }
            if (model.planEndDate == null || model.planEndDate == DateTime.MinValue)
            {
                parameters[2].Value = DBNull.Value;
            }
            else
            {
                parameters[2].Value = model.planEndDate;
            }
            if (model.completeDate == null || model.completeDate == DateTime.MinValue)
            {
                parameters[3].Value = DBNull.Value;
            }
            else
            {
                parameters[3].Value = model.completeDate;
            }
            if (model.principal == null)
            {
                parameters[4].Value = DBNull.Value;
            }
            else
            {
                parameters[4].Value = model.principal;
            }


            int rows = SqlHelper.ExecuteNonQuery(Comm.Config.PMS, CommandType.Text, strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="projectID"></param>
        /// <returns></returns>
        public List<PMS_ProjectEvolve> GetList(string projectID)
        {
            string sql = "select * from PMS_ProjectEvolve where isDelete='0' and projectID=@projectID order by orders";
            SqlParameter[] parameters = { new SqlParameter("@projectID", projectID) };
            return SqlHelper.GetDataByColumnsLst<PMS_ProjectEvolve>(Comm.Config.PMS, sql, parameters);
        }

        #endregion  Method
    }
}

